// 实现 Object.assign 这个函数就是实现浅拷贝

let obj = {
  name: "xiaolidu",
  age: 20,
  hobby: ['吃饭', '睡觉', '打豆豆'],
  power: {
    sleep: '8小时',
    eat: "20个馒头"
  }
}
// Object.assign2 = function (targrt, ...source) {
//   if (targrt === null) {
//     throw new TypeError('Cannot convert undefined or null to object')
//   }
//   let ret = Object(targrt)
//   source.forEach(function (obj) {
//     if (obj !== null) {
//       for (let key in obj) {
//         if (obj.hasOwnProperty(key)) {
//           ret[key] = obj[key]
//         }
//       }
//     }
//   })
//   return ret
// }
Object.assign2 = function (targrt, ...source) {
  let ret = Object(targrt)
  source.forEach(function (obj) {
    if (obj !== null) {
      for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
          ret[key] = obj[key]
        }
      }
    }
  })
  return ret
}
let obj1 = { age: 30 }
let newObj = Object.assign2(obj1, obj)
newObj.hobby.push('吹牛')
newObj.power.sleep = '10小时'
console.log(obj1);
console.log('----------------------');
console.log(newObj);